# from PySide6.QtCore import QThread, Signal
# from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton, QTextEdit, QVBoxLayout, QWidget

# class WorkerThread(QThread):
#     progress_updated = Signal(int)

#     def __init__(self, parent=None):
#         super().__init__(parent)

#     def run(self):
#         # 执行耗时操作
#         for i in range(0,100,5):
#             # 发送进度信号
#             self.progress_updated.emit(i)
#             self.msleep(100)  # 模拟耗时操作

# class MainWindow(QMainWindow):
#     def __init__(self):
#         super().__init__()

#         self.setWindowTitle("Large File Execution")
#         self.setGeometry(100, 100, 400, 300)

#         self.button = QPushButton("Start", self)
#         self.button.clicked.connect(self.start_execution)

#         self.text_edit = QTextEdit(self)

#         layout = QVBoxLayout()
#         layout.addWidget(self.button)
#         layout.addWidget(self.text_edit)

#         central_widget = QWidget()
#         central_widget.setLayout(layout)
#         self.setCentralWidget(central_widget)

#     def start_execution(self):
#         self.button.setEnabled(False)

#         # 创建并启动工作线程
#         self.worker_thread = WorkerThread()
#         self.worker_thread.progress_updated.connect(self.update_progress)
#         self.worker_thread.finished.connect(self.execution_finished)
#         self.worker_thread.start()

#     def update_progress(self, progress):
#         self.text_edit.append(f"Progress: {progress}%")

#     def execution_finished(self):
#         self.button.setEnabled(True)
#         self.text_edit.append("Execution finished")

# if __name__ == "__main__":
#     app = QApplication([])
#     window = MainWindow()
#     window.show()
#     app.exec()

import sys
from PySide6.QtCore import Qt, QThread, Signal
from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton, QLabel

class WorkerThread(QThread):
    update_signal = Signal(str)

    def run(self):
        # 在这里执行耗时的操作
        for i in range(10):
            self.update_signal.emit(f"Processing {i+1}")
            self.msleep(1000)  # 模拟耗时操作

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        self.setWindowTitle("Tool")
        self.setGeometry(100, 100, 300, 200)

        self.label = QLabel(self)
        self.label.setAlignment(Qt.AlignCenter)
        self.label.setGeometry(50, 50, 200, 30)

        self.button = QPushButton("Start", self)
        self.button.setGeometry(100, 100, 100, 30)
        self.button.clicked.connect(self.start_thread)

        self.worker_thread = WorkerThread()
        self.worker_thread.update_signal.connect(self.update_label)

    def start_thread(self):
        self.button.setEnabled(False)
        self.worker_thread.start()

    def update_label(self, text):
        self.label.setText(text)

        if text == "Processing 10":
            self.button.setEnabled(True)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
    sys.exit(app.exec())
